package de.kardass.jannobatch.skiprepeatabort;

import de.kardass.jannobatch.errorhandler.ErrorHandler;
import de.kardass.jannobatch.errorhandler.ErrorHandlerReturnCode;
import de.kardass.jannobatch.errorhandler.HandledError;

public class SkipRepeatAbortErrorHandler implements ErrorHandler<WorkflowItem, Throwable> {

    public HandledError<WorkflowItem, Throwable> handleException(WorkflowItem item, Throwable exception) {
        if (exception instanceof AbortJobException) {
            return new HandledError<WorkflowItem, Throwable>(item, exception, ErrorHandlerReturnCode.ABORT_BATCH);
        } else if (exception instanceof RepeatFirstStepException) {
            return new HandledError<WorkflowItem, Throwable>(item, exception, ErrorHandlerReturnCode.REPEAT_CURRENT_STEP);
        } else if (exception instanceof SkipFirstStepException) {
            return new HandledError<WorkflowItem, Throwable>(item, exception, ErrorHandlerReturnCode.CONTINUE_WITH_NEXT_STEP);
        } else if (exception instanceof SkipItemException) {
            return new HandledError<WorkflowItem, Throwable>(item, exception, ErrorHandlerReturnCode.CONTINUE_WITH_NEXT_ITEM);
        } else {
            throw new IllegalStateException("Never come here!");
        }
    }

}
